package com.qx.dao;

import java.util.List;
import java.util.Map;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import com.qx.entity.Modules;

public interface ModulesDao extends JpaRepository<Modules, Integer>,JpaSpecificationExecutor<Modules> {
	
	List<Modules> findByParentidIsNull();
	
	List<Modules> findByParentid(Integer parentid);
	
	@Query(value="select Id,Name from modules",nativeQuery=true)
	List<Map<String, String>> getSelAll();
	
	//不同用户登录显示不同模块
	@Transactional
	@Modifying
	@Query(value="SELECT m.name,m.parentid,m.path FROM users u,userroles ur,roles r,modules m,rolemodules rm WHERE r.id=ur.roleid AND u.id=ur.userid AND m.id=rm.moduleid AND r.id=rm.roleid AND u.loginname=?1 ",nativeQuery=true)  
	public List<Map<String, Object>> getUserMo(String name);	
}
